import type { Directive, App } from 'vue';
import { router as globalRoute } from '@/router';
/** 按钮权限 */
export default function AuthButtonDirective(app: App) {
    const AuthButton: Directive<HTMLElement, string | undefined> = {
        mounted(el: HTMLElement, binding) {
            const { fullPath, matched } = globalRoute.currentRoute.value;
            const currentRoutePathData = matched[0]?.children.find(item => item.path === fullPath) as {
                [key in string]: any;
            };
            if (!Object.keys(currentRoutePathData).length) {
                return false;
            }
            const { button: authLimit } = currentRoutePathData;
            if (!authLimit.includes(binding.value)) {
                el?.parentNode?.removeChild(el);
            }
        }
    };
    app.directive('limit', AuthButton);
}
